package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import entity.Grade;
import util.DBUtil;

public class GradeDao {
	public List<Grade> findALL() {

		String sql = "select * from s_grade order by id ";

		List<Grade> datas = new ArrayList<>();
		Connection con = DBUtil.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;

		try {
			ps = con.prepareStatement(sql);

			rs = ps.executeQuery();
			while (rs.next()) {
				Grade g = new Grade();
				g.setId(rs.getLong("id"));
				g.setGname(rs.getString("gname"));
				datas.add(g);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs);
			DBUtil.close(ps);
			DBUtil.close(con);
		}
		return datas;
	}
}
